#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2012/06/16

@author: António Baião

Classe responsavel por fazer a reserva de indices para que se possa
contruir a árvore
'''
class Stack:
        def __init__(self, N):
                self.top = -1
                self.S = [None for k in range(N)]
              
                pass
        
        def stack_empty(self):
                if self.top == 0:
                        return True
                else:
                        return False
        
        def push(self, x):
                self.top += 1
                self.S[self.top] = x
                pass
        
        def pop(self):
                if self.stack_empty():
                        return "underflow"
                else:
                        self.top -= 1
                        
                        return self.S[self.top+1]
                pass
        def __str__(self):
                s = ""
                s += str(self.top+1) + ": "
                for k in range(0, self.top+1):
                        s += ' ' + str(self.S[k])
                return s
        pass